package com.phonepn.mymall.goods.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * token拦截器
 *
 * @author quifar
 */
@Slf4j
public class TokenInterceptor extends HandlerInterceptorAdapter {

    @Value("${patterns}")
    private String[] patterns;

    /**
     * controller 执行之前调用,返回true 往下执行,否则不往下执行
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        // 非拦截路径
        String path = request.getRequestURI();

        if (patterns.length > 0) {
            for (String p : patterns) {
                if (path.contains(p)) return true;
            }
        }

        System.err.println("进入拦截器");
        return true;
    }

}
